home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / xlib03.zip / XDETECT.ASM < prev    next >
Assembly Source File  |  1993-04-05  |  4KB  |  156 lines

  1. ;-----------------------------------------------------------------------
  2. ; MODULE XDETECT
  3. ;
  4. ; Hardware detection module
  5. ;
  6. ; Compile with Tasm.
  7. ; C callable.
  8. ;
  9. ;
  10. ; ****** XLIB - Mode X graphics library                ****************
  11. ; ******                                               ****************
  12. ; ****** Written By Themie Gouthas                     ****************
  13. ; ****** Aeronautical Research Laboratory              ****************
  14. ; ****** Defence Science and Technology Organisation   ****************
  15. ; ****** Australia                                     ****************
  16. ;
  17. ; egg@dstos3.dsto.gov.au
  18. ; teg@bart.dsto.gov.au
  19. ;-----------------------------------------------------------------------
  20. LOCALS
  21. .286
  22.  
  23. include model.inc
  24. include xdetect.inc
  25.  
  26.  
  27.     .code
  28.  
  29.  
  30. i86       equ 0
  31. i186      equ 1
  32. i286      equ 2
  33. i386      equ 3
  34.  
  35.  
  36. NONE      equ 0
  37. MDA       equ 1
  38. CGA       equ 2
  39. EGAMono   equ 3
  40. EGAColor  equ 4
  41. VGAMono   equ 5
  42. VGAColor  equ 6
  43. MCGAMono  equ 7
  44. MCGAColor equ 8
  45.  
  46. PS2_CARDS db  0,1,2,2,4,3,2,5,6,2,8,7,8
  47.  
  48.  
  49. ;-----------------------------------------------------------------------
  50. ; PC Graphics detection routine. Returns graphics card type
  51. ;
  52. ; C callable as:
  53. ;    unsigned int x_graphics_card();
  54. ;
  55. ;
  56.  
  57. proc _x_graphics_card
  58.     push bp                  ; Preserve caller's stack frame
  59.     mov  ax,1A00h            ; Try calling VGA Identity Adapter function
  60.     int  10h
  61.     cmp  al,1Ah              ; Do we have PS/2 video bios ?
  62.     jne  @@not_PS2           ; No!
  63.  
  64.     cmp  bl,0Ch              ; bl > 0Ch => CGA hardware
  65.     jg   @@is_CGA            ; Jump if we have CGA
  66.     xor  bh,bh
  67.     xor  ah,ah
  68.     mov  al,cs:PS2_CARDS[bx] ; Load ax from PS/2 hardware table
  69.     jmp  short @@done        ; return ax
  70. @@is_CGA:
  71.     mov  ax,CGA              ; Have detected CGA, return id
  72.     jmp  short @@done
  73. @@not_PS2:                       ; OK We don't have PS/2 Video bios
  74.     mov  ah,12h              ; Set alternate function service
  75.     mov  bx,10h              ; Set to return EGA information
  76.     int  10h                 ; call video service
  77.     cmp  bx,10h              ; Is EGA there ?
  78.     je   @@simple_adapter    ; Nop!
  79.     mov  ah,12h              ; Since we have EGA bios, get details
  80.     mov  bl,10h
  81.     int  10h
  82.     or   bh,bh               ; Do we have colour EGA ?
  83.     jz   @@ega_color         ; Yes
  84.     mov  ax,EGAMono          ; Otherwise we have Mono EGA
  85.     jmp  short @@done
  86. @@ega_color:
  87.     mov  ax,EGAColor         ; Have detected EGA Color, return id
  88.     jmp  short @@done
  89. @@simple_adapter:
  90.     int  11h                 ; Lets try equipment determination service
  91.     and  al,30h
  92.     shr  al,4
  93.     xor  ah,ah
  94.     or   al,al               ; Do we have any graphics card at all ?
  95.     jz   @@done              ; No ? This is a stupid machine!
  96.     cmp  al,3                ; Do We have a Mono adapter
  97.     jne  @@is_CGA            ; No
  98.     mov  ax,MDA              ; Have detected MDA, return id
  99. @@done:
  100.     pop  bp                  ;restore caller's stack frame
  101.     ret
  102. _x_graphics_card endp
  103.  
  104.  
  105. ;-----------------------------------------------------------------------
  106. ; PC Processor detection routine
  107. ;
  108. ; C callable as:
  109. ;    unsigned int x_processor();
  110. ;
  111. ;
  112. proc _x_processor
  113.     pushf                    ; Save flags
  114.     xor  ax,ax         ; Clear AX
  115.     push ax                  ; Push it on the stack
  116.     popf                     ; Zero the flags
  117.     pushf                    ; Try to zero bits 12-15
  118.     pop  ax                  ; Recover flags
  119.         and  ax,0F000h           ; If bits 12-15 are 1 => i86 or i286
  120.         cmp  ax,0F000h
  121.         jz   is_86_186
  122.  
  123.         mov  ax,07000h           ; Try to set bits 12-14
  124.         push ax
  125.         popf
  126.         pushf
  127.         pop  ax
  128.         and  ax,07000h           ; If bits 12-14 are 0 => i286
  129.         jz   is_286
  130.  
  131.         mov  ax,i386             ; We have a 386
  132.         jmp  short @@done
  133.  
  134. is_286:
  135.         mov  ax,i286             ; We have a 286
  136.         jmp  short @@done
  137.  
  138. is_86_186:                       ; Determine whether i86 or i186
  139.         push cx                  ; save CX
  140.         mov  ax,0FFFFh           ; Set all AX bits
  141.         mov  cl,33               ; Will shift once on 80186
  142.         shl  ax,cl               ; or 33 x on 8086
  143.         pop  cx
  144.         jnz  is_186              ; 0 => 8086/8088
  145. is_86:
  146.         mov  ax,i86
  147.         jmp  short @@done
  148. is_186:
  149.         mov  ax,i186
  150. @@done:
  151.     popf
  152.     ret
  153. _x_processor endp
  154.     end
  155.  
  156.